<?php
class class_form
{
	//Khai bao bien

	function class_form()	
	{
		//global ;
		//Khoi tao bien
		
	}
	//thay the gia tri nhu submit file, button...
	function loadtemplate($arr)
	{
		$html = "";
		$html = loadHtml($arr["layout_html"],"");
		if (count($arr) > 0){
			foreach ($arr as $key=>$value){
				//$$key = $value;	//gan gia tri vao bien
				$pattern = "@$key@";
				$replacement = "$value";
				$html = ereg_replace($pattern, $replacement, $html);
			}//end for
		}
		return $html;
	}
	
	function view($layout)
	{
		global $langid, $barid;
		
		$html = loadHtml($layout,"");

		$html = ereg_replace("@langid@","$langid",$html);
		$html = ereg_replace("@barid@", "$barid",$html);
		
		return $html;
	}//	popup_print	


	function sendmail($layout="", $layout2="", $arr_to=array())
	{
		global $debug, $arr_noidung, $langid, $arr_nut, $url, $langid
		;
		$muaban = new class_muaban();
		
		$subject = $arr_noidung["subject"];
		
		$mail_from = $arr_noidung["email"];
		$mail_to_1 = STORE_OWNER_EMAIL_ADDRESS;
		$mail_to_2 = SEND_EXTRA_ORDER_EMAILS_TO;
		//$mail_to_2 = "";
		$mail_to_3 = "info@trawenic.com";
		
		if ($debug){
			echo $noidung;
			echo"<br>";
			echo "mail_to_1: $mail_to_1<br>";
			echo "mail_to_2: $mail_to_2<br>";
			echo "mail_to_3: $mail_to_3<br>";
		}
		
		
		//print_r ($arr_noidung);
		if(count($arr_to)>0){
			//print_r ($arr_to);
			foreach($arr_to as $nguoiban_id){
				$arr_nd = $arr_noidung;				
				$arr_thongtin_nguoiban = $muaban->arr_thongtin_nguoiban($nguoiban_id);
				
				$arr_nd["brand"] = $arr_thongtin_nguoiban["brand"];
				$arr_nd["product_type"] = $arr_thongtin_nguoiban["product_type"];
				$arr_nd["model"] = $arr_thongtin_nguoiban["model"];
				$arr_nd["description"] = $arr_thongtin_nguoiban["description"];
				
				$mail_to = $arr_thongtin_nguoiban["email"];
				$noidung = $this->noidung($layout2, $arr_nd);
				if($mail_to != ""){			
					//echo "$noidung<br>";		
					tep_mail_html($mail_to,$mail_to,$subject,$noidung,$mail_from,$mail_from);

					tep_mail_html($mail_to_1,$mail_to_1,$subject,$noidung,$mail_from,$mail_from);
					tep_mail_html($mail_to_3,$mail_to_3,$subject,$noidung,$mail_from,$mail_from);
					if ($mail_to_2!="" ){
						tep_mail_html($mail_to_2,$mail_to_2,$subject,$noidung,$mail_from,$mail_from);
					}			


				}
			}
		}else{
			$noidung = $this->noidung($layout2);
			//tep_mail_html($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address)
			tep_mail_html($mail_to_1,$mail_to_1,$subject,$noidung,$mail_from,$mail_from);
			tep_mail_html($mail_to_3,$mail_to_3,$subject,$noidung,$mail_from,$mail_from);
			if ($mail_to_2!="" ){
				tep_mail_html($mail_to_2,$mail_to_2,$subject,$noidung,$mail_from,$mail_from);
			}			
		}
		
			
		$html = loadHtml($layout,"");
		
		return $html;		
	}//end sendmail

	function noidung($layout="", $arr_nd=array())
	{
		global $arr_noidung, $debug, $langid;
		$html = "";
		$html = loadHtml($layout,"");
		if(count($arr_nd) > 0){
			$arr_noidung_ = $arr_nd;
		}else{
			$arr_noidung_ = $arr_noidung;
		}
		if (count($arr_noidung_) > 0){
			foreach ($arr_noidung_ as $key=>$value){
				//$$key = $value;	//gan gia tri vao bien
				$pattern = "@$key@";
				$replacement = "$value";
				$html = ereg_replace($pattern, $replacement, $html);
			}//end for
		}
		if ($debug){
			//echo $html;
		}
		return $html;	
	} // end noidung

}//end class_form
?>